/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Bakul;

import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author gatz
 */
public class BakulTabelModel extends AbstractTableModel {
        private List<Bakul> bakuls = new ArrayList<Bakul>();

    public BakulTabelModel(List<Bakul> bakul2) {
        this.bakuls = bakul2;
    }

    public void deleteBakul(int row){
        bakuls.remove(row);
        fireTableRowsDeleted(row, row);
    }

    public void updateBakul(int row, Bakul bakul){
        bakuls.set(row,bakul);
        fireTableRowsUpdated(row, row);
    }

    public void addBakul(Bakul bakul) {
        bakuls.add(bakul);
        fireTableRowsInserted(getRowCount() - 1, getColumnCount() - 1);
    }

    public int getRowCount() {
        return bakuls.size();
    }

    
    public int getColumnCount() {
        return 2;
    }
    
    public Object getValueAt(int rowIndex, int columnIndex) {
        Bakul b = bakuls.get(rowIndex);
        switch (columnIndex) {
            case 0:
                return b.getIdBakul();
            case 1:
                return b.getNamaBakul();
            default:
                return "";
        }
    }

    @Override
    public String getColumnName(int column) {
        switch (column) {
            case 0:
                return "ID BAKUL";
            case 1:
                return "NAMA BAKUL";
            default:
                return "";
        }
    }
}
